package com.wy2.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.wy2.entity.Student;
import com.wy2.entity.User;
import com.wy2.util.FenyeUtil;

@Repository
public interface StudentMapper {

	/**
	 * 查询条数
	 * @param fenye
	 * @return
	 */
		Integer getCount(FenyeUtil<Student> fenye);
	/**
	 * 查询数据
	 * @param fenye
	 * @return
	 */
		List<Student> getData(FenyeUtil<Student> fenye);
	/**
	 * 添加学生
	 * @param s
	 * @return
	 */
		Integer addStudent(Student s);
	/**
	 * 删除
	 * @param sid
	 * @return
	 */
		Integer delStudent(Integer sid);
	/**
	 * 修改
	 * @param s
	 * @return
	 */
		Integer updStudent(Student s);
	/**
	 * 通过id查询数据
	 * @param id
	 * @return
	 */
		@Select("select * from student where sid = #{id}")
		List<Student> findById(String id);
	/**
	 * 不带分页的查询全部
	 * @return
	 */
		@Select("select * from student")
		List<Student> findAll();
	/**
	 * 按条件的添加方法
	 * @param s
	 * @return
	 */
		@Insert("insert into student(wlid,sname,sage,sex,stel,sedu,sqq)values(#{wlid},#{sname},#{sage},#{sex},#{stel},#{sedu},#{sqq})")
		Integer importSingin(Student s);
	/**
	 * 通过id修改
	 * @param sid
	 * @return
	 */
		Integer updateExt(Integer sid);
	/**
	 * 带分页查询全部数据
	 * @param fenye
	 * @return
	 */
		List<Student> findByExt(FenyeUtil<Student> fenye);
	/**
	 * 查询条数
	 * @param fenye
	 * @return
	 */
		Integer getCountExt(FenyeUtil<Student> fenye);

		Integer stuExt(Integer sid, String ext);

		// 查询所有的咨询师
		@Select("SELECT * from student stu INNER JOIN `user` u on stu.zxid = u.uid"
				+ " INNER JOIN userrole ur on ur.uid = u.uid INNER JOIN role r on r.rid = ur.rid where r.rname = '咨询师' GROUP BY u.uname")
		List<User> getZXS();

		// 查询所有的咨询师
		@Select("SELECT * from clock dk INNER JOIN `user` u on dk.uid = u.uid INNER JOIN userrole ur on ur.uid = u.uid "
				+ "INNER JOIN role r on r.rid = ur.rid where r.rname = '咨询师' and dk.cstatus = '已打卡' and dk.checkintime >= #{time} "
				+ "GROUP BY u.uname")
		List<User> getZXSFP(String time);

		// 分配设置
		Integer upFP(String zxsname, String zxid, @Param("ids") List<String> idList);

		// 获取未分配的学生信息
		@Select("select * from student where zxsname = #{zxsname}")
		List<Student> getAllWFP(String zxsname);

		// 自动分配设置
		Integer upZDFP(String zxsname, String zxid, Integer ids);
	// 获取未分配的学生信息
	@Select("select * from student where zxsname = #{zxname}")
	List<Student> findByZxName(String zxname);
//根据id修改咨询师字段
	@Update("update student set zxsname = #{ask} where sid = #{sid}")
	void updateZxNameById(String ask, Integer sid);
	
	List<Student> getSname(FenyeUtil<Student> fenye);

}
